This invention relates to a file system that the self-repair by file management is allowed during the operation of a computer system, and more particularly to, a file management method for file systems that allows the self-repair during the operation of system even when there occurs an inconsistency due to the stop of system.
At present, there are a variety of file systems, such as the UNIX file system, that are used on computers. However, if the system stops when the structure of file system is being changed as in case of addition or removal of file, there may occur an inconsistency in the structure of file system and thereby some access to the file may not be allowed. Also, it is difficult to repair the inconsistency in the structure of file system during the operation of system, therefore many systems need to conduct the repair procedure of file system for a long time before using the file system. Since there are some systems such as a switching exchange system that it is undesirable to do the repair of file system for such a long time during the processing to re-start the system, a file system that the self-repair is allowed even during the operation of system has been desired.
FIG. 1 illustrates an inconsistency in a conventional structure of file system. For example, files 34, 36 each consist of five data blocks (each of which is composed of multiple physical blocks to retain data). In the file system, it is assumed that file 36 is made after the system re-starts by reason that the system stops when file 34 is being changed. In this case, file 34 and file 36 may use a same data block 38 under the influence of the stop of the system. If the content of file 36 is rewritten while the data block overlaps each other, the content of file 34 must be altered. In such a state, it is impossible to guarantee the content of file. This state is the inconsistency in the structure of file system.
Japanese patent application laid-open No. 10-63555 (1998) discloses a file management method for file system. In the file management method disclosed, its area-allotting block number list always saves the number of a head block of file. In each block of data storage area, data and its next-linked block number or an identifier to represent an empty block is recorded. The file management program allots an additional empty block when adding new data to file.
Thus, when the system re-starts after the file-writing processing is discontinued, the file management program traces a head block number in area and the next block number of each block to an empty block, thereby restoring its file management table.
Some file systems such as the UNIX file system use an area, such as i node (index node), for managing the data block. This i node enables the file system to know the position of a data block. In such a file system, if the system stops when the structure of file system is being changed, there may occur a discordance between a data block on magnetic disk to store data and data block information of the i node for file management. In the conventional file systems, the occurrence of discordance must cause an inconsistency. So, it is necessary for the file system to conduct the repair procedure during the re-start processing of the system in order to solve the inconsistency. However, there is a problem that the repair procedure conducted by the file system takes a considerable time.
Also, in the file management method disclosed in Japanese patent application laid-open No. 10-63555, when re-starting the system, it is required to restore the file processing.
Accordingly, it is an object of the invention to provide a file management method for file system that allows the self-repair during the operation of system even when there occurs an inconsistency due to the stop of system.
According to the invention, a file management method for a file system that a storage device is provided with a plurality of data blocks to store data, and the storage device and the main memory of a computer is provided with a management block to save in-use information about whether a data block is in use or not, in-transition information about whether the content of data block is being changed or not, and information about whether an adjacent data block is used as a sequential area or not, comprises the steps of:
checking the in-use information of the management block on the main memory when securing a second data block so as to store data relating to a first data block, when an unused area is found, setting the in-transition information of the unused area to be in transition and the in-use information to be in use;
initializing an area to manage a data block in the second data block;
storing the position of the first data block into the area to manage a data block in the second data block;
storing the position of the second data block into an area to manage a data block in the first data block;
copying the information of the management block on the main memory to the management block on the storage device; and
removing the in-transition information.
According to another aspect of the invention, a file management method for a file system that a storage device is provided with a plurality of data blocks to store data, and the storage device and the main memory of a computer is provided with a management block to save in-use information about whether a data block is in use or not, in-transition information about whether the content of data block is being changed or not, and information about whether an adjacent data block is used as a sequential area or not, comprises the steps of:
checking the in-use information of the management block on the main memory when storing data continuously into an adjacent area to a data block, when the unused adjacent area is found, setting the in-use information to be in use and information about whether a continuous area is continuously expanded to be continuously expanded;
copying the information of the management block on the main memory to the management block on the storage device; and
storing information about up to which position of the area to store data effective data is saved into the area to manage the data block in the data block.